package jsoup;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.IOException;

/**
 * @Author 汤舒青
 * @Version 1.0
 */


public class JsoupTest02 {
    //从网络获取
    public static void main(String[] args) {
        String url="https://www.baidu.com/";
        Document document = null;
        try {
            document = Jsoup.connect(url).get();
            System.out.println(document.outerHtml());
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
    //从本地解析
    @Test
    public void test() throws IOException {
        File file = new File("D:\\IdeaProjects\\javau1\\jsoup\\src\\bdqn.html");
        Document parse = Jsoup.parse(file, "utf-8");
        System.out.println(parse);
        Elements img = parse.getElementsByTag("img");
        for (Element element : img) {
            System.out.println(element);
            String src = element.attr("src");
            String href = element.attr("href");

            System.out.println("src属性值"+src);
            System.out.println("href属性值"+href);

        }


    }
}
